package com.gigi.controller;

import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.Response;
import com.gigi.enums.ErrorCodeEnum;
import com.gigi.model.ExamineRequest;
import com.gigi.model.ExtraDO;
import com.gigi.model.ListExamineRequest;
import com.gigi.service.manual.ExtraManageService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 补签申请管理
 */
@RestController
@RequestMapping("extra-manage")
public class ExtraManageController {

    private final ExtraManageService extraManageService;

    public ExtraManageController(ExtraManageService extraManageService) {
        this.extraManageService = extraManageService;
    }

    @ApiOperation(value = "新增")
    @PostMapping("/insert")
    public Response insert(@RequestBody @Valid ExtraDO request) {
        return extraManageService.insert(request);
    }

    @ApiOperation(value = "学生补签申请列表")
    @PostMapping("/list-for-student")
    public MultiResponse<ExtraDO> listForStudent(@RequestBody @Valid ListExamineRequest request) {
        return extraManageService.listForStudent(request);
    }

    @ApiOperation(value = "老师补签申请列表")
    @PostMapping("/list-for-teacher")
    public MultiResponse<ExtraDO> listForTeacher(@RequestBody @Valid ListExamineRequest request) {
        return extraManageService.listForTeacher(request);
    }

    @ApiOperation(value = "审批")
    @PostMapping("/examine")
    public Response examine(@RequestBody @Valid ExamineRequest request) {
        try {
            extraManageService.examine(request);
        } catch (Exception e) {
            System.out.println(e);
            return Response.buildFailure(ErrorCodeEnum.EDIT_FAILED.getErrCode(), ErrorCodeEnum.EDIT_FAILED.getErrDesc());
        }
        return Response.buildSuccess();
    }

}
